import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { UsersModule } from './modules/users/users.module';
import { OrderModule } from './modules/order/order.module';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { databaseConfig } from '@/config/database.config'; 
import { TypeOrmModule } from '@nestjs/typeorm';
import { JwtAuthGuard } from '@/common/authentication/JwtAuthGuard';
import { JwtModule } from '@nestjs/jwt'; 
import { KeyGeneratorService } from "@/common/services/key-generator.service";
import { ResponseInterceptor } from '@/common/interceptor/response.interceptor';
@Module({
  imports: [
    UsersModule,
    OrderModule,
    ConfigModule.forRoot({
      isGlobal: true,
    }),
    TypeOrmModule.forRootAsync({
      imports: [ConfigModule],
      useFactory: databaseConfig,
      inject: [ConfigService],
    }),
    JwtModule.registerAsync({
      imports: [ConfigModule],
      useFactory: async (configService: ConfigService) => ({
        secret: configService.get<string>('SECRET_KEY'), // 从配置中获取密钥
        signOptions: { expiresIn: '60s' },
      }),
      inject: [ConfigService],
    }),
  ],
  controllers: [AppController],
  providers: [AppService, JwtAuthGuard, KeyGeneratorService,ResponseInterceptor],
})
export class AppModule {}
